package com.sharemob.tinchat.base;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;

public abstract class BaseActivityGroup extends FragmentActivity {

	 private List<Fragment> fragments=new ArrayList<Fragment>();
	 public FragmentManager fragmentManager;  
	 public FragmentTransaction fragmentTransaction;
	 
	 public void addFragmentManager(Fragment object){
		 fragments.add(object);
	 }
	    public void cropImageUri(Uri uri, int outputX, int outputY, int requestCode){
	        Intent intent = new Intent("com.android.camera.action.CROP");
	        intent.setDataAndType(uri, "image/*");
	        intent.putExtra("crop", "true");
	        intent.putExtra("aspectX", 2);
	        intent.putExtra("aspectY", 1);
	        intent.putExtra("outputX", outputX);
	        intent.putExtra("outputY", outputY);
	        intent.putExtra("scale", true);
	        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
	        intent.putExtra("return-data", false);
	        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
	        intent.putExtra("noFaceDetection", true); // no face detection
	        startActivityForResult(intent, requestCode);
	    }
		public void BtnEvent(int id,final Callback callback){
			   findViewById(id).setOnClickListener(new OnClickListener()
		        {
		            public void onClick(View v)
		            {
		            	callback.doDown();
		            }
		        });
		}

	 public void exitView(int id,final int animId,final int exitAnim){
	        findViewById(id).setOnClickListener(new OnClickListener()
	        {
	            public void onClick(View v)
	            { 
	            	finish();
	            	//关闭窗体动画显示
	                overridePendingTransition(exitAnim,animId);
	            }
	        });
	    }
	 public void hideAllFragment(){
		 fragmentTransaction = fragmentManager.beginTransaction();
		 for(Fragment fragment:fragments){
			 fragmentTransaction.hide(fragment);
		 }
	 }
	 
	 public void showFragment(int index){
		 hideAllFragment();
		 fragmentTransaction.show(fragments.get(index)).commit();
	 }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        fragmentManager = getSupportFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        
//        MobclickAgent.onError(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
//        MobclickAgent.onResume(this);
//        activityManager.dispatchResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
//        MobclickAgent.onPause(this);
//        activityManager.dispatchPause(isFinishing());
    }

    @Override
    protected void onStop() {
        super.onStop();
//        activityManager.dispatchStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        activityManager.dispatchDestroy(isFinishing());
    }

}
